package com.xunk.system.controller;

import com.xunk.common.core.web.domain.AjaxResult;
import com.xunk.system.service.ISysSceneService;
import com.xunk.system.vo.FixSceneVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ProjectName: xunk
 * @Package: com.xunk.buz.controller
 * @ClassName: SysSceneController
 * @Author: dongxiaoxin
 * @Description: 场景控制
 * @Date: 2021/4/6 14:24
 * @Version: 1.0
 */
@RestController
@RequestMapping("/scene")
public class SysSceneController {

    @Autowired
    ISysSceneService service;

    /**
     *  批量控制设备
     * @param  fixSceneVo
     * @return  操作结果
     */
    @PostMapping("/control")
    public AjaxResult fixScene(@RequestBody FixSceneVo fixSceneVo){
        return service.controlFixScene(fixSceneVo);
    }

    /**
     *
     * @return
     */
    @PostMapping("/perform")
    public AjaxResult performSceneNow(@RequestBody FixSceneVo sceneVo){
        return service.performSceneNow(sceneVo.getCode(),sceneVo.getHomeId());
    }

    @GetMapping("/devices")
    public AjaxResult getDeviceList(Long homeId,String code){
        return AjaxResult.success(service.getDeviceList(homeId,code));
    }

    @GetMapping("/list")
    public AjaxResult getFixScene(Long homeId,String position){
        return AjaxResult.success(service.getSceneList(homeId,position));
    }

    @PostMapping("/save")
    public AjaxResult saveScene(@RequestBody FixSceneVo fixSceneVo){
        service.saveSceneDetail(fixSceneVo);
        return AjaxResult.success();
    }

    @GetMapping("/remove")
    public AjaxResult removeSceneFromIndex(String code,Long homeId){
        service.updateScenePosition(code,homeId,0);
        return AjaxResult.success();
    }

}
